package org.fffd.l23o6.util.strategy.payment;

import io.github.lyc8503.spring.starter.incantation.exception.BizException;
import org.fffd.l23o6.exception.BizError;
import org.fffd.l23o6.util.paystub.AlipayStub;

import java.math.BigDecimal;

public class WechatPayStrategy extends PaymentStrategy{
    public static final WechatPayStrategy INSTANCE = new WechatPayStrategy();

    @Override
    public int init() {
        return 0;
    }

    //TODO
    @Override
    public boolean pay(Long id, BigDecimal amount, Long userId) {
        //使用桩的情形
        AlipayStub.PayResult result = AlipayStub.pay(amount);
        if (result == AlipayStub.PayResult.LACK_OF_BALANCE) {
            throw new BizException(BizError.OUT_OF_MONEY);
        }
        if (result == AlipayStub.PayResult.ERROR) {
            throw new BizException(BizError.PAYMENT_FAILURE);
        }

        return false;
    }

    @Override
    public boolean refund(BigDecimal amount) {
        AlipayStub.PayResult result = AlipayStub.refund(amount);
        if (result == AlipayStub.PayResult.ERROR) {
            throw new BizException(BizError.REFUND_FAILURE);
        }

        return false;
    }
}
